﻿using ExcelTools.Core.NPOI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ExcelTools.Test.WinForm
{
    public partial class frmExcelImport : Form
    {
        public frmExcelImport()
        {
            InitializeComponent();
        }

        private void btnExportExcel_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog file = new FolderBrowserDialog();
            if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                ExportOp op = new ExportOp(file.SelectedPath + Guid.NewGuid().ToString() + ".xls", "测试", Core.NPOI.Enum.ExcelTypeEnum.Xls);
                op.CreateRow(0, new Dictionary<int, Core.NPOI.Model.ExcelColumn>() { 
                    {0,new Core.NPOI.Model.ExcelColumn() { Value="序号",Algin= Core.NPOI.Enum.HorizontalAlignmentEnum.Center, IsBold=true, IsHeader=true, Type= Core.NPOI.Enum.ColumnTypeEnum.String }},
                    {1,new Core.NPOI.Model.ExcelColumn() { Value="名称",Algin= Core.NPOI.Enum.HorizontalAlignmentEnum.Center, IsBold=true, IsHeader=true, Type= Core.NPOI.Enum.ColumnTypeEnum.String }},
                    {2,new Core.NPOI.Model.ExcelColumn() { Value="创建时间",Algin= Core.NPOI.Enum.HorizontalAlignmentEnum.Center, IsBold=true, IsHeader=true, Type= Core.NPOI.Enum.ColumnTypeEnum.String }},
                    {3,new Core.NPOI.Model.ExcelColumn() { Value="状态",Algin= Core.NPOI.Enum.HorizontalAlignmentEnum.Center, IsBold=true, IsHeader=true, Type= Core.NPOI.Enum.ColumnTypeEnum.String }}
                });
                for (int i = 1; i < 10; i++)
                {
                    op.CreateRow(i, new Dictionary<int, Core.NPOI.Model.ExcelColumn>() { 
                        {0,new Core.NPOI.Model.ExcelColumn() { Value=i.ToString(),Algin= Core.NPOI.Enum.HorizontalAlignmentEnum.Center, IsBold=true, IsHeader=true, Type= Core.NPOI.Enum.ColumnTypeEnum.String }},
                        {1,new Core.NPOI.Model.ExcelColumn() { Value="test"+i.ToString(),Algin= Core.NPOI.Enum.HorizontalAlignmentEnum.Center, IsBold=true, IsHeader=true, Type= Core.NPOI.Enum.ColumnTypeEnum.String }},
                        {2,new Core.NPOI.Model.ExcelColumn() { Value=DateTime.Now.ToShortDateString(),Algin= Core.NPOI.Enum.HorizontalAlignmentEnum.Center, IsBold=true, IsHeader=true, Type= Core.NPOI.Enum.ColumnTypeEnum.String }},
                        {3,new Core.NPOI.Model.ExcelColumn() { Value=new Random().Next(5).ToString(),Algin= Core.NPOI.Enum.HorizontalAlignmentEnum.Center, IsBold=true, IsHeader=true, Type= Core.NPOI.Enum.ColumnTypeEnum.String }}
                    });
                }
                op.Write();
            }
        }
    }
}
